#include <stdio.h>


void inplace_swap(int *x, int *y) {
	// printf("*x = %d\n", *x);
	// printf("x = %d\n", x);
	*y = *x ^ *y; /* step 1 */
	*x = *x ^ *y; /* step 2 */
	*y = *x ^ *y; /* step 3 */
}

void reverse_array(int a[], int cnt) {
	int first, last;
	for(first = 0, last = cnt - 1; first < last; first++, last--)
		inplace_swap(&a[first], &a[last]);
}


int main()
{	
	int a = 3;
	int b = 4;

	inplace_swap(&a, &b);
	printf("a = %d, b = %d\n", a, b);

	int arr[] = {1, 2, 3, 4, 5};
	reverse_array(arr, 5);
	
	int i;
	for(i = 0; i < 5; i++)
		printf(" %d", arr[i]);
	printf("\n");

	return 0;
}
